import { Model } from 'sequelize';
import sequelize from '../config/db.js';
import User from './user.js';
import { DataTypes } from 'sequelize';

class ActivityData extends Model {}
ActivityData.init(
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    steps: {
      type: DataTypes.INTEGER,
      defaultValue: 0
    },
    distance: {
      type: DataTypes.DECIMAL(10, 2),
      defaultValue: 0
    },
    calories: {
      type: DataTypes.INTEGER,
      defaultValue: 0
    },
    activeTime:{
      type: DataTypes.INTEGER,
      defaultValue: 0
    },
    collectTime: {
      type: DataTypes.DATE,
      defaultValue: DataTypes.NOW,
    },
  },
  {
    sequelize,
    modelName: 'ActivityData',
    tableName: 'activity_data',
  }
);

ActivityData.belongsTo(User, { foreignKey: 'userId', as: 'user' });
User.hasMany(ActivityData, { foreignKey: 'userId', as: 'activityData' });

export default ActivityData;